from django.urls import reverse
from web import models
from django.template import Library
register=Library()

@register.inclusion_tag('web/inclusion/all_project_list.html')
def all_project_list(request):
    all_project_queryset=models.Project.objects.filter(creator=request.tracer.user)
    join_project_queryset=models.ProjectUser.objects.filter(user=request.tracer.user)
    return {'my':all_project_queryset,'join':join_project_queryset}

@register.inclusion_tag('web/inclusion/manage_menu_list.html')
def manage_menu_list(request):
    data_list=[
        {'title':'概览','url':reverse('web:manage:dashboard',kwargs={'project_id':request.tracer.project.id})},
        {'title': '问题', 'url': reverse('web:manage:issues', kwargs={'project_id': request.tracer.project.id})},
        {'title': '统计', 'url': reverse('web:manage:statistics', kwargs={'project_id': request.tracer.project.id})},
        {'title': 'wiki', 'url': reverse('web:manage:wiki', kwargs={'project_id': request.tracer.project.id})},
        {'title': '文件', 'url': reverse('web:manage:file', kwargs={'project_id': request.tracer.project.id})},
        {'title': '配置', 'url': reverse('web:manage:setting', kwargs={'project_id': request.tracer.project.id})},
    ]
    for item in data_list:
        if request.path_info.startswith(item['url']):
            item['class']='active'
    return {'data_list':data_list}